//
//  WZGAplyIntoView.m
//  ZCJZ
//
//  Created by 潘洪波 on 2020/2/27.
//  Copyright © 2020 jeking. All rights reserved.
//

#import "WZGAplyIntoView.h"
#import <UILabel+Flex.h>
@implementation WZGAplyIntoViewModel



@end

@interface WZGAplyIntoView ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) UILabel *titleLab ;
@property (nonatomic, strong) UILabel *desLab ;
@property (nonatomic, strong) UIView *bgView ;

@property (nonatomic, strong) WZGAplyIntoViewModel *model ;
@end


@implementation WZGAplyIntoView


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissSelf)];
        [self addGestureRecognizer:tap];
        tap.delegate = self;
    }
    return self;
}

#pragma mark ---- gestureDelegate ----
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if ([touch.view isDescendantOfView:self.bgView]) {
        return NO;
    }
    return YES;
}

- (void)dismissSelf{
    UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
    [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:10 options:options animations:^{
        self.bgView.transform = CGAffineTransformMakeScale(0.001, 0.001);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (void)setModel:(WZGAplyIntoViewModel *)model{
    [self.titleLab setFlexAttrString:model.title name:@"tt"];
    [self.titleLab updateAttributeText];
    self.desLab.text = model.des;
}

+ (void)showIntroViewWithModel:(WZGAplyIntoViewModel*)model{
    UIWindow *keyW = [[UIApplication sharedApplication] keyWindow];
    WZGAplyIntoView *view = [[WZGAplyIntoView alloc] initWithFlex:nil Frame:keyW.bounds Owner:nil];
    view.model = model;
    [keyW addSubview:view];
    view.bgView.transform = CGAffineTransformMakeScale(0.0001, 0.0001);
    UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
    [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:options animations:^{
        view.bgView.transform = CGAffineTransformMakeScale(1, 1);
    } completion:^(BOOL finished) {
        
    }];
}

@end
